package com.deco.back.controller.brand;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import tk.mybatis.mapper.util.StringUtil;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.deco.domain.vo.brand.ActivityReportVo;
import com.deco.domain.vo.fix.FixGeneralVo;
import com.deco.domain.vo.fix.FixTypeVo;
import com.deco.service.brand.ActivityReportService;
import com.free.common.vo.PageResponseVo;
import com.free.common.vo.PageSearchVo;
import com.free.common.vo.ResultModel;
import com.free.ext.web.spring.annoation.PageSearch;

@Controller
public class ActivityReportController {

	@Autowired
	ActivityReportService activityReportService;
	
	
	 /**
     * View视图
     */
    @RequestMapping(value="/activity_report_list")
    public ModelAndView active_report() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("brand/activereportlist");
        return modelAndView;
    }
    
    @RequestMapping(value= "/activityreport/pageInfo")
    @ResponseBody
    public PageResponseVo<ActivityReportVo> getList(@PageSearch PageSearchVo<ActivityReportVo> condition){
        return activityReportService.pageInfo(condition);
    }
    
    /**
     *  删除活动报告
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/activityreport/batchdelete")
    public ResultModel batchDelete(HttpServletRequest request) {
    	String ids = request.getParameter("ids");
    	String[] idArray =  ids.split(",");

    	return activityReportService.batchDelete(idArray);
    }
    
    /**
     *  删除活动报告
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/activityreport/delete")
    public ResultModel delete(HttpServletRequest request) {
    	Long id = Long.parseLong(request.getParameter("id"));

    	return activityReportService.delete(id);
    }
    
    /**
     *  保存更新活动报告
     * @param req
     * @param activeReportVo
     * @return
     */
    @RequestMapping(value="/activity_report_edit_submit.do")
    @ResponseBody
    public ResultModel save(HttpServletRequest req ,ActivityReportVo activeReportVo) {
    	return activityReportService.save(activeReportVo);
    }
    
    
    /**
     *  保存更新活动报告
     * @param req
     * @param activeReportVo
     * @return
     */
    @RequestMapping(value="/activity_report_status")
    @ResponseBody
    public ResultModel updateStatus(HttpServletRequest req ,ActivityReportVo activeReportVo) {
    	return activityReportService.save(activeReportVo);
    }
    
	 /**
     * View视图
     */
    @RequestMapping(value="/activity_report_edit")
    public ModelAndView activeEdit(HttpServletRequest req,Long id) {
    	 ModelAndView mv = new ModelAndView("brand/activereportedit");
    	ActivityReportVo vo = null;
    	 if(id != null){
    		vo =  activityReportService.getActivityReport(id);
            mv.addObject("actNm","更新");
    	}
    	 else{
    	     vo = new ActivityReportVo();
    	     vo.setId(0L);
    	     vo.setReporTime(new Date());
             mv.addObject("actNm","新增");
    	 }
        mv.addObject("obj", vo);
        return mv;
    }

}
